<?php
$del = isset($_GET['del']) ? $_GET['del'] : "";
$pro_Id = isset($_GET['product_id']) ? $_GET['product_id'] : "";
if (!empty($del) && !empty($pro_Id)) {
    $delete = mysql_query("UPDATE tbl_order_item porderi, tblproduct_in_pharmacy pip
                            SET porderi.user_histoStatusDel = 0
                            WHERE pip.pid=porderi.pd_id
                            AND porderi.od_id = '" . $del . "'
                            AND pip.product_id = '" . $pro_Id . "' ");
    
     header('Location: index.php');
}

$content = 'user_shopping_history.php';

?>

<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<style>
    .toggler
    {
        margin: 10px 0 0 0;
    }
    .button {
        text-decoration: none;
    }
    .point
    {
        cursor: pointer;
    }
    #effect {
        position: relative;
        padding: 0.4em;
    }
    h3.statistic {
        margin: 0;
        padding: 0.4em;
        text-align: left;
        font-size: 14px;
        display:block;
    }
    .t_none
    {
        border:none;
    }
    .notread
    {
        color:#000;
        font-weight: bold;
    }
    .read
    {
        color:#999;
        font-weight:normal;
        background:#eee!important;
    }
    a {color:#000;}
    tr:hover
    {
        background: #ddd!important;
    }

</style>

<div class="row">
<!--    <div style="margin: 10px 15px 0 0;">-->
        <h3 class="statistic ui-widget-header ui-corner-all"><!--shopping activity--><?php echo 'Shopping Activities' ?></h3>
        <form name="frmlist">
        <table cellpadding="0" cellspacing="0" border="0" width="100%" class="table">
            <tr style="background-color: #CCC">
                <th width="5%" align="center">No</th>
                <th width="17%" align="center">Shopping Date</th>
                <th width="15%" align="center">Shop Name</th>
                <th width="25%" align="center">Address</th>
                <th width="12%" align="center">Phone</th>
                <th width="17%" align="center">Web site</th>
                <th width="15%" align="center">Status</th>
                <th width="10%" align="center">Action</th>
            </tr>
        </table>

        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">

            <?php
            $qstring = '';
            $rowsPerPage = isset($_GET['num']) ? $_GET['num'] : '10';
            
            $sql = "SELECT phar.pharmacy_name, phar.website, phar.address, phar.phone, porder.od_date, porderi.oi_status, porder.od_id, pip.status, pip.product_id
                                FROM tbl_order_item AS porderi
                                INNER JOIN tbl_order AS porder ON porderi.od_id=porder.od_id
                                INNER JOIN tblproduct_in_pharmacy AS pip ON pip.pid=porderi.pd_id
                                INNER JOIN tblproduct AS pro ON pro.id=pip.product_id
                                INNER JOIN tblpharmacy AS phar ON phar.user_id=pro.owner
                                INNER JOIN tbluser AS u ON u.id=porder.user_id
                                WHERE porder.user_id = '" . $_SESSION['acc_id'] . "' AND porderi.user_histoStatusDel = 1 ORDER BY porderi.od_id ASC";
            
            $ch_ord = mysql_query(getPagingQuery($sql, $rowsPerPage));            
            $pagingLink = getPagingLink($sql, $rowsPerPage, $qstring);            
            $i = 1;           
            $n = 0;     
            $page = (!empty($_GET['page'])) ? $_GET['page'] : '0';
            $nomlist = (!empty($page)) ? $rowsPerPage * $page - 10 : '0';
            while ($rows = mysql_fetch_assoc($ch_ord)) {   
                $n++;
                extract($rows);
                    if ($i % 2) {
                        $class = 'row1';
                    } else {
                        $class = 'row2';
                    }
                ?>
                <tr class="<?php echo $class ?>">
                    <td width="5%" align="center"><a href="<?php echo W_ROOT; ?>/user_activity/product_shopping.php?id=<?php echo $rows['od_id']; ?>&product_id=<?php echo $rows['product_id'] ?>"><?php echo $n + $nomlist; ?></a></td>					
                    <td width="15%" align="center"><a href="<?php echo W_ROOT; ?>/user_activity/product_shopping.php?id=<?php echo $rows['od_id']; ?>&product_id=<?php echo $rows['product_id'] ?>"><?php echo $rows['od_date']; ?></a></td>
                    <td width="15%" align="center"><a href="<?php echo W_ROOT; ?>/user_activity/product_shopping.php?id=<?php echo $rows['od_id']; ?>&product_id=<?php echo $rows['product_id'] ?>"><?php echo $rows['pharmacy_name']; ?></a></td>
                    <td width="25%" align="center"><a href="<?php echo W_ROOT; ?>/user_activity/product_shopping.php?id=<?php echo $rows['od_id']; ?>&product_id=<?php echo $rows['product_id'] ?>"><?php echo $rows['address']; ?></a></td>
                    <td width="12%" align="center"><a href="<?php echo W_ROOT; ?>/user_activity/product_shopping.php?id=<?php echo $rows['od_id']; ?>&product_id=<?php echo $rows['product_id'] ?>"><?php echo $rows['phone']; ?></a></td>
                    <td width="17%" align="center"><a href="<?php echo W_ROOT; ?>/user_activity/product_shopping.php?id=<?php echo $rows['od_id']; ?>&product_id=<?php echo $rows['product_id'] ?>"><?php echo $rows['website']; ?></a></td>
                    <td width="15%" align="center"><strong>
                            <?php
                            if ($rows['oi_status'] == 0) {
                                echo "<a style='color: red; font-weight:bold' title='Not pay yet'>In Progress";
                            } else if ($rows['oi_status'] == 1) {
                                echo '<a style="color: blue; font-weight:bold">Paid';
                            }
                            ?>
                        </a></td>
                    <td style="width: 10px;padding:10px"><a title="delete" href="<?php echo W_ROOT; ?>/user_activity/index.php?del=<?php echo $rows['od_id']; ?>&product_id=<?php echo $rows['product_id'] ?>"><i class="icon-remove"></i></a></td>
                </tr>
                <?php
                $i++;
            } //End while
            ?>

        </table>
        <div class="row-fluid">
                <div class="span7">
                    <div class="wp-pagenavi">
                        <?php echo $pagingLink; ?>
                        <div class="clear"></div>
                    </div>
                </div>
                <div class="span3 offset2">
                    view per page
                    <select class="right span4" name="numpage" onchange="javascript:viewByNumPage();">
                        <option value="10" <?php echo($rowsPerPage == 10) ? ' selected="selected"' : ''; ?>>10</option>
                        <option value="20" <?php echo($rowsPerPage == 20) ? ' selected="selected"' : ''; ?>>20</option>
                        <option value="30" <?php echo($rowsPerPage == 30) ? ' selected="selected"' : ''; ?>>30</option>
                        <option value="40" <?php echo($rowsPerPage == 40) ? ' selected="selected"' : ''; ?>>40</option>
                        <option value="50" <?php echo($rowsPerPage == 50) ? ' selected="selected"' : ''; ?>>50</option>        
                    </select>
                </div>            
            </div> 
        </form>
<!--    </div>-->
</div>

